package cn.lili.modules.payment.entity.dto;

import cn.lili.common.security.enums.SceneEnums;
import cn.lili.common.utils.StringUtils;
import cn.lili.modules.order.order.entity.dos.OrderFlow;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 分佣积分列表
 */
@Data
@Builder
public class OutFmoneyOrderItem {


    @ApiModelProperty(value = "昵称")
    private String nickname;

    @ApiModelProperty(value = "用户ID")
    private String userId;

    @ApiModelProperty(value = "分账接收方类型")
    private SceneEnums scene;

    @ApiModelProperty(value = "分账金额")
    private Double price;

    @ApiModelProperty(value = "订单号")
    private String orderSn;


    // 根据订单获取所有待分账用户
    public static List<OutFmoneyOrderItem> generateItems(OrderFlow orderFlow) {

        List<OutFmoneyOrderItem> outOrderItems = new ArrayList<>();


        if (orderFlow.getStoreId() != null && orderFlow.getFmoney() != null && orderFlow.getFmoney() > 0) {
            outOrderItems.add(OutFmoneyOrderItem.builder()
                    .scene(SceneEnums.STORE).nickname(orderFlow.getStoreName()).price(orderFlow.getFmoney())
                    .orderSn(orderFlow.getOrderSn())
                    .userId(orderFlow.getStoreId()).build());
        }


//        outOrderItems.add(OutPointOrderItem.builder().userId("-1").nickname("平台佣金").scene(SceneEnums.SYSTEM)
//                .orderSn(orderFlow.getOrderSn()).price(orderFlow.getPlatformSettlementPrice()).build());


        return outOrderItems;
    }


    public String generateDescription() {
        return switch (this.scene) {
            case MEMBER -> String.format("[%s]推广获利-订单[%s]-分账[%s元]", this.nickname, this.orderSn, StringUtils.formatPrice(this.price));
            case STORE -> String.format("[%s]店铺-订单[%s]-分账[%s元]", this.nickname, this.orderSn, StringUtils.formatPrice(this.price));
            case SUPPLIER -> String.format("[%s]供应商-订单[%s]-分账[%s元]", this.nickname, this.orderSn, StringUtils.formatPrice(this.price));
            case SYSTEM -> String.format("[%s]-订单[%s]-分账[%s元]", this.nickname, this.orderSn, StringUtils.formatPrice(this.price));
            default -> "";
        };
    }

    public String generateReduceDescription() {
        return "平台余额扣除:" + generateDescription();
    }

}
